<%@ page import="com.guotd.ticketSystem.entity.Order" %>
<%@ page import="java.util.List" %>
<%@page pageEncoding="UTF-8" contentType="text/html; UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>订单列表</title>
    <link rel="stylesheet" href="css/list2.css">
</head>
<body>
<%int type = (int) session.getAttribute("type"); %>
    <% List<Order> orders = (List<Order>) request.getAttribute("orders");
    String flightId= request.getParameter("flightId");%>
    <%
        if (session.getAttribute("order_msg") != null)
        {
    %>
    <h2><%= session.getAttribute("order_msg") %></h2>
    <%
        }
    %>
    <% if (type==2)
    {
    %>
    <a href="flight_add.jsp" class="table-button">添加航班信息</a>
    <a href="index_admin.jsp" class="table-button">回到主页</a>
    <%
        }
    %>
    <% if (type==1)
    {
    %>
    <a href="index_user.jsp" class="table-button">回到主页</a>
    <%
        }
    %>
<table>
    <tr>
        <th>订单号</th>
        <th>用户id</th>
        <th>乘客证件号</th>
        <th>乘客姓名</th>
        <th>航班</th>
        <th>客舱</th>
        <th>起飞日期</th>
        <th>起飞时间</th>
        <th>出发机场</th>
        <th>到达机场</th>
        <th>订单状态</th>
        <th colspan="2">操作</th>
    </tr>
    <%
        if(orders!=null){
            for (Order o : orders) {
            String status = "未支付";
            if(o.getStatus()==1) {
                status = "未支付";
            }if(o.getStatus()==2) {
                status="已支付";
            }if(o.getStatus()==3) {
                status="已取消";
            }
    %>
    <tr>
        <td><%=o.getId() %></td>
        <td><%=o.getUser().getId() %></td>
        <td><%=o.getPassenger().getIdentity() %></td>
        <td><%=o.getPassenger().getName() %></td>
        <td><%=o.getFlight().getName() %></td>
        <td><%=o.getCabin().getName() %></td>
        <td><%=o.getFlight().getSchedule().getFromDate() %></td>
        <td><%=o.getFlight().getSchedule().getFromTime() %></td>
        <td><%=o.getFlight().getAirline().getFromAirport() %></td>
        <td><%=o.getFlight().getAirline().getToAirport() %></td>
        <td><%=status %></td>
        <% if (type==2)
        {
        %>
        <td> <a href="orderDel?id=<%=o.getId()%>&&flightId=<%=flightId%>" class="table-button">删除订单</a> </td>
        <%
            }
        %>
        <% if (type==1)
        {
        %>
        <td> <a href="payOrder?id=<%=o.getId()%>&&userId=<%=o.getUser().getId() %>" class="table-button">支付</a> </td>
        <td> <a href="cancelOrder?id=<%=o.getId()%>&&userId=<%=o.getUser().getId() %>" class="table-button">取消订单</a> </td>
        <%
            }
        %>
    </tr>
    <%
            }
        }
    %>
</table>
</body>
</html>